/**
 *  Author: songyy
 *
 *  At every run, this would get the report for yesterday, check with database if there're existing
 *  records. If there're, then just return; if don't have, then this file would auto download the
 *  corresponding js files and build up the log structure in the Mondb.
 */

    // Build up the config
var config = require("./config.js");
var util = require("util");
var DB_PATH = "mongodb://localhost:27017/" + config.dbName;

function print2d(n){
    var sn = String(n);
    if(n < 10)  return "0" + sn;
    return sn;
}

/**
 * Build the URL from the date, The date is set to yesterday.
 */
function buildReportJsonPath(pathWithFormat){
    // get day, month, year
    var d = new Date(); var monD = d.getMonth();
    return pathWithFormat
        .replace("%year%",d.getFullYear())
        .replace("%monD%",print2d(monD+1))
        .replace("%monL%",(config.monthWordArr[monD]))
        .replace("%day%",print2d(d.getDate()));
}


console.log("Path Str: " + buildReportJsonPath(config.reportPath));


/*
    // Run the DB -- do the query check existance of the record of today
MongoClient.connect(config.dbName,function(err,db){
    if(err)	return console.dir(err);    // TODO: further error handling might need.

    console.log("DB Connected");
    // The main logic comes here.
}
 */


